import time

from view.ths_view.simulated_view import SimulatedView
from view.ths_view.ashare_view import AshareView
from common import appium_desired, multi_appium_desired
from common import logger


def main(driver):
    try:
        logger.info("开始启动APP")
        s = AshareView(driver)
        time.sleep(5)
        s.enter_simulated_buy()
        s.click_holdings_tab()
        while True:
            input_str = input("请输入一段可运行的代码：")
            if input_str:
                exec(input_str)
            else:
                time.sleep(1)
    except Exception as e:
        logger.info(e)




def real_main(driver):
    try:
        t = AshareView(driver)
        t.check_close_btn()
        t.click_transaction_tab()
        t.login()
    finally:
        driver.close_app()


if __name__ == '__main__':
    # 模拟单设备测试
    driver = appium_desired('ths_desired_caps.yaml')
    main(driver)

    # 多设备测试
    # device_dict = {"4723": ["夜神模拟器", "127.0.0.1:62001", True],
    #                # "4725": "127.0.0.1:62025",
    #                }
    # fen_list = []
    # for num in range(100):
    #     try:
    #         f = 0
    #         driver_list = multi_appium_desired('multi_desired_caps.yaml', device_dict)
    #         for i in driver_list:
    #             f = main(i)
    #             # real_main(i)
    #     except:
    #         pass
    #     fen_list.append(f)
    # import statistics
    # logger.info(fen_list)
    # logger.info(f"最低:{min(fen_list)}分")
    # logger.info(f"平均:{statistics.mean(fen_list)}分")
    # logger.info(f"众数:{statistics.mode(fen_list)}分")
    # logger.info(f"中位数:{statistics.median(fen_list)}分")

    # 实盘测试
    # driver = appium_desired('ths_desired_caps.yaml')
    # real_main(driver)
